<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>数据查询</title>
<link href="styles/general.css" rel="stylesheet" type="text/css" /><link href="styles/main.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/common.js"></script>
    <script src="js/utils.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/jquery/uploadify/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquerytablesorter/jquery.tablesorter.min.js"></script>
	<script language="javascript" type="text/javascript" src="js/DatePicker4.72/WdatePicker.js"></script>

<link rel="stylesheet" type="text/css" href="http://ajax.pupkk.com/dojo/1.7.5/dojo/resources/dojo.css" />
	<link rel="stylesheet" type="text/css" href="http://ajax.pupkk.com/dojo/1.7.5/dijit/themes/tundra/tundra.css" />
	<script src="http://ajax.pupkk.com/dojo/1.7.5/dojo/dojo.js" djConfig="parseOnLoad:true"></script>
    <script type="text/javascript">
		dojo.require("dojo.parser");
		dojo.require("dijit.form.DateTextBox");
		dojo.require("dijit.form.FilteringSelect");
		function get_query_dimension(dc)
		{
			var dimension = "";
			for (var n = 0; n < dc; n++)
			{
				var id = "dimension[" + n + "]";
				if (document.getElementById(id))
				{
					if(document.getElementById(id).checked)
					{
						if (dimension.length > 0)
							dimension += ";";
						dimension += document.getElementById(id).value;
					}
				}
			}
			return dimension;
		}
		function save()
		{
			var dimension = get_query_dimension(7);
			document.getElementById("dimension").value=dimension;
			if(document.getElementById("startdate").value=="")
			{
				alert("选择要查询的日期!");
				return false;
			}
			if(document.getElementById("enddate").value=="")
			{
				alert("选择要查询的日期!");
				return false;
			}
			return true;
			
		}
		function changeappversion(val){
			$.get("channeldataquery_changeappversion.do?appid="+val,function(data){
				$("#appversiondiv").html(data);
			});
		}
	</script>
</head>

<body>
<h1>
        <span class="action-span"></span> <span
            class="action-span1"><a href="mainframe.jsp">
                首页</a> </span><span id="search_id" class="action-span1">- 导入数据渠道查询</span>
    </h1>
    <form name="form1" id="form1" method="post" action="channeldataquery_query.do?type=query" onsubmit="return save();">
    <input type="hidden" id="dimension" name="dimension" />
    <div class="form-div"   style="margin-bottom: 5px;width: 100%;" align="center">
        <table width="90%"  cellspacing="1" cellpadding="2" > 
            <tbody>
				<tr height="30">
					<td>开始日期：</td>
					<td align="left"><input type="text" size="25" name="startdate" id="startdate" 
					    onFocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd',skin:'whyGreen'})" 
					    onblur="formvalidator(this)" value="<s:property value="startdate" />"/></td>
					<td>结束日期：</td>
					<td align="left"><input type="text" size="25" name="enddate" id="enddate" 
					    onFocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd',skin:'whyGreen'})" 
					    onblur="formvalidator(this)" value="<s:property value="enddate" />"/></td>
					<td>运营商：</td>
					<td align="left">
						<select style="width:180px;" name="operator" id="operator" >
							<option value="">--请选择--</option>
							<option <s:if test='operator.equals("中国移动")'>selected</s:if> value="中国移动">中国移动</option>
							<option <s:if test='operator.equals("中国联通")'>selected</s:if> value="中国联通">中国联通</option>
							<option <s:if test='operator.equals("中国电信")'>selected</s:if> value="中国电信">中国电信</option>
						</select>
					</td>
					<td rowspan="3" align="left">
					  <input id="dimension[0]" type="checkbox" value="day" checked ><label for="dimension[0]">日&nbsp;&nbsp;&nbsp;&nbsp;期</label>
					  &nbsp;<input id="dimension[1]" type="checkbox" value="operator" <s:if test="dimension.indexOf('operator')>-1">checked</s:if>><label for="dimension[1]">运营商</label>
					  &nbsp;<input id="dimension[6]" type="checkbox" value="province" <s:if test="dimension.indexOf('province')>-1">checked</s:if>><label for="dimension[6]">省&nbsp;&nbsp;&nbsp;&nbsp;份</label>
			          <br>
			          <br>
			          <input id="dimension[2]" type="checkbox" value="appid" <s:if test="dimension.indexOf('appid')>-1">checked</s:if>><label for="dimension[2]">游&nbsp;&nbsp;&nbsp;&nbsp;戏</label>
			          &nbsp;<input id="dimension[4]" type="checkbox" value="appvid" <s:if test="dimension.indexOf('appvid')>-1">checked</s:if>><label for="dimension[4]">版&nbsp;&nbsp;&nbsp;&nbsp;本</label>
			          &nbsp;<input id="dimension[3]" type="checkbox" value="channelid" <s:if test="dimension.indexOf('channelid')>-1">checked</s:if>><label for="dimension[3]">渠&nbsp;&nbsp;&nbsp;&nbsp;道</label>
			          <br>
			          <br>
			          <input id="dimension[5]" type="checkbox" value="source" <s:if test="dimension.indexOf('source')>-1">checked</s:if>><label for="dimension[5]">收入来源</label>
          			  <br>
					</td>
				</tr>
				<tr height="30">
				<td>游戏：</td>
					<td align="left">
						<select id="appid" name="appid" onchange="changeappversion(this.value);" dojoType="dijit.form.FilteringSelect">
			               <option value="">--请选择--</option>
			               <s:iterator value="applist" status="stat">
			               <option value="<s:property value="appnumber" />" <s:if test="appnumber.equals(appid)">selected</s:if>><s:property value="appname" /></option>
			               </s:iterator>
			             </select>
					</td>
					<td>发行版本：</td>
					<td align="left"><div id="appversiondiv"><jsp:include page="_changeappversion.jsp" /></div></td>
					<td>渠道：</td>
					<td align="left">
						<select id="channelid" name="channelid" dojoType="dijit.form.FilteringSelect">
			               <option value="-1">--请选择--</option>
			               <s:iterator value="channellist" status="stat">
			               <option value="<s:property value="id" />" <s:if test="id.equals(channelid)">selected</s:if>><s:property value="name" /></option>
			               </s:iterator>
			             </select>
					</td>
				</tr>
				<tr height="30">
					<td>收入来源：</td>
					<td align="left">
						<select name="source" id="source" dojoType="dijit.form.FilteringSelect" >
							<option value="">--请选择--</option>
							<s:iterator value="terracelist">
							<option <s:if test='source.equals(operatorsName)'>selected</s:if> value="<s:property value="operatorsName" />"><s:property value="operatorsName" /></option>
							</s:iterator>
						</select>
					</td>
					<td>省份：</td>
					<td align="left"><input type="text" size="25" name="province" id="province" 
					     value="<s:property value="province" />"/></td>
				</tr>
				<tr>
					<td align="center" colspan="7"><input type="submit" value=" 查询 " class="button" /></td>
				</tr>
			</tbody>
		</table>
	</div>
   <!-- start ad menu list -->
    <div class="list-div" id="listDiv" style="margin-bottom: 5px;width: 100%;" align="center">
    	<s:if test="'query'.equals(type)">
        <table width="90%" id="myTable" cellspacing="1" cellpadding="2" align="center">
          <thead>
                <tr>
                	<s:if test="%{checkQueryDimension(dimension,'day')}">
                    <th height="20">日期</th>
                    </s:if>
                    <s:if test="%{checkQueryDimension(dimension,'appid')}">
                    <th>游戏</th>
                    </s:if>
                    <s:if test="%{checkQueryDimension(dimension,'appvid')}">
                    <th>发行版本</th>
                    </s:if>
                    <s:if test="%{checkQueryDimension(dimension,'channelid')}">
				    <th>渠道</th>
				    </s:if>
				    <s:if test="%{checkQueryDimension(dimension,'bd')}">
				    <th>负责人</th>
				    </s:if>
                    <s:if test="%{checkQueryDimension(dimension,'goodsname')}">
				    <th>计费点</th>
				    </s:if>
                    <s:if test="%{checkQueryDimension(dimension,'operator')}">
				    <th>运营商</th>
				    </s:if>
                    <s:if test="%{checkQueryDimension(dimension,'source')}">
				    <th>收入来源</th>
				    </s:if>
                    <s:if test="%{checkQueryDimension(dimension,'province')}">
				    <th>省份</th>
				    </s:if>
				    <th>收入</th>
				    <th>新增用户</th>
				    <th>活跃用户</th>
				    <th>付费用户</th>
				    <th>付费次数</th>
				    <th>ARPU</th>
                </tr>
                </thead>
                <s:if test="list.size()>0">
                <s:set name="newuserscount" value="0"></s:set>
                <s:set name="activeusercount" value="0"></s:set>
                <s:set name="payingcustomerscount" value="0"></s:set>
                <s:set name="paidnumbercount" value="0"></s:set>
                <tbody>
  				<s:iterator value="list" status="i"> 
  					 <tr>
  					 		<s:if test="%{checkQueryDimension(dimension,'day')}">
                            <td style="background-color: rgb(255, 255, 255);">
                            <s:property value="day"/>
                            </td>
                            </s:if>
                    		<s:if test="%{checkQueryDimension(dimension,'appid')}">
                            <td style="background-color: rgb(255, 255, 255);">
                            	<s:iterator value="applist1">
                            		<s:if test="appnumber.equals(list.get(#i.count-1).appnumber)"><s:property value="appname"/></s:if>
                             	</s:iterator>
                            </td>
                            </s:if>
                            <s:if test="%{checkQueryDimension(dimension,'appvid')}">
                            <td style="background-color: rgb(255, 255, 255);">
                            	<s:iterator value="appvlist">
                            		<s:if test="appversionnumber.equals(list.get(#i.count-1).appversionnumber)"><s:property value="appname"/></s:if>
                             	</s:iterator>
                            </td>
                            </s:if>
                   			 <s:if test="%{checkQueryDimension(dimension,'channelid')}">
                            <td style="background-color: rgb(255, 255, 255);">
                            <s:property value="%{getchannelname(channelid)}"/>
                            </td>
                            </s:if>
                            <s:if test="%{checkQueryDimension(dimension,'bd')}">
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:if test="bd==''">未知</s:if>
						    	<s:else>
						    	<s:property value="bd"/>
						    	</s:else>
						    </td> 
						    </s:if>
                    		<s:if test="%{checkQueryDimension(dimension,'goodsname')}">
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:if test="goodsname==''">未知</s:if>
						    	<s:else>
						    	<s:property value="goodsname"/>
						    	</s:else>
						    </td> 
						    </s:if>
                    		<s:if test="%{checkQueryDimension(dimension,'operator')}">
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:if test="operator==''">未知</s:if>
						    	<s:else>
						    	<s:property value="operator"/>
						    	</s:else>
						    </td>
						    </s:if>
                    		<s:if test="%{checkQueryDimension(dimension,'source')}">
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:if test="source==''">未知</s:if>
						    	<s:else>
						    	<s:property value="source"/>
						    	</s:else>
						    </td>
						    </s:if>
                    		<s:if test="%{checkQueryDimension(dimension,'province')}">
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:if test="province==''||province=='null'">未知</s:if>
						    	<s:else>
						    	<s:property value="province"/>
						    	</s:else>
						    </td>
						    </s:if>
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:property value="%{formatfee(fee)}"/>
						    </td>
						     <td style="background-color: rgb(255, 255, 255);">
						    	<s:property value="newusers"/>
						    </td>
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:property value="activeuser"/>
						    </td>
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:property value="payingcustomers"/>
						    </td>
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:property value="paidnumber"/>
						    </td>
						    <td style="background-color: rgb(255, 255, 255);">
						    	<s:property value="%{computearpu(fee,activeuser)}"/>
						    </td>
						    <s:set name="newuserscount" value="#newuserscount+newusers"></s:set>
						     <s:set name="activeusercount" value="#activeusercount+activeuser"></s:set>
						      <s:set name="payingcustomerscount" value="#payingcustomerscount+payingcustomers"></s:set>
						       <s:set name="paidnumbercount" value="#paidnumbercount+paidnumber"></s:set>
  					</tr>
  				</s:iterator>
  				</tbody>
  				</s:if>
  				<tr>
  					 <td style="background-color: rgb(255, 255, 255);"colspan="<s:property value="%{getQueryDimensionCount(dimension)}"/>">合计
                            </td>
                      <td style="background-color: rgb(255, 255, 255);">
                            <s:property value="%{formatfee(totalfee)}"/>
                            </td>
                            <td style="background-color: rgb(255, 255, 255);">
                            	<s:property value="#newuserscount"/>
                            </td>
                            <td style="background-color: rgb(255, 255, 255);">
                            	<s:property value="#activeusercount"/>
                            </td>
                            <td style="background-color: rgb(255, 255, 255);">
                            	<s:property value="#payingcustomerscount"/>
                            </td>
                            <td style="background-color: rgb(255, 255, 255);">
                            	<s:property value="#paidnumbercount"/>
                            </td>
                            <td style="background-color: rgb(255, 255, 255);">
                            	<s:property value="%{computearpu(totalfee,#activeusercount)}"/>
                            </td>
  				</tr>
		  </table>
		  </s:if>
  </div>
  </form>
 <!--Bottom开始-->
    <script language="JavaScript">

if (document.getElementById("listDiv"))
{
  document.getElementById("listDiv").onmouseover = function(e)
  {
    obj = Utils.srcElement(e);

    if (obj)
    {
      if (obj.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode;
      else if (obj.parentNode.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode.parentNode;
      else return;

      for (i = 0; i < row.cells.length; i++)
      {
        if (row.cells[i].tagName != "TH") row.cells[i].style.backgroundColor = '#eeeded';
      }
    }

  }

  document.getElementById("listDiv").onmouseout = function(e)
  {
    obj = Utils.srcElement(e);

    if (obj)
    {
      if (obj.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode;
      else if (obj.parentNode.parentNode.tagName.toLowerCase() == "tr") row = obj.parentNode.parentNode;
      else return;

      for (i = 0; i < row.cells.length; i++)
      {
          if (row.cells[i].tagName != "TH") row.cells[i].style.backgroundColor = '#FFF';
      }
    }
  }

}
$(document).ready(function() {
	   $("#myTable").tablesorter();
	});
    </script>
    
<div id="footer">
<br />
<s:property value="bottom"/></div>
    <!--Bottom结束-->
</body>
</html>